package configuration

import (
	"encoding/json"
	"fmt"
	"kop/modules/configuration/client"
	"kop/util/log"
)

func init() {

	var b = client.Load("StageMain")
	if err := json.Unmarshal(b, &Configs); err != nil {
		panic(err)
	}

	for k := range Configs {

		Configs[k].CoinRates = append([]float64{1}, Configs[k].CoinRates...)
	}

	log.Info("Load StageMain.json success.")

}

type Conf struct {
	StageID   int32     `json:"ID"` // 任务ID
	NeedLevel int32     // 等级要求
	CD        int32     // 冷却时间
	Power     int64     // 副本战力
	StepCount int32     // 阶段
	CostCoin  int64     // 每步移动消耗银币基础
	CoinRates []float64 //
	Gold      int32     `json:"AwardGold"` // 奖励金币
	AwardID   int32     // 奖励ID
	BossID    int32     // 首领ID
	BossLevel int32     // 首领等级
}

func (s Conf) MaxStep() int32 {
	return s.StepCount * 5
}

var Configs = map[int32]*Conf{}

func GetByStageID(stageID int32) (Conf, error) {

	var conf, ok = Configs[stageID]
	if ok {
		return *conf, nil
	}

	return Conf{}, fmt.Errorf("StageID not found [%d]", stageID)
}
